﻿@model Models.Models.CouponList
@using WebApp.Classes;
@using Models.Models;

@{
    ViewBag.Title = "Coupon Settings";

    var user = new UserCookie().Get().User;

    var domains = new WebApp.Services.DomainService().GetStoreIPList(new Store() { ID = user.StoreID }, 1, 1000000, "Name", "ASC", true).DomainList;
    var domainList = new SelectList(domains.List, "ID", "Name");    
    
     string domainId = ViewBag.DomainID.ToString();
}

@Scripts.Render("~/scripts/jquery.validate.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.js")
@Scripts.Render("~/scripts/partialViewValidation.js")

@Scripts.Render("~/scripts/jquery-ui-1.8.11.min.js")

@Styles.Render("~/Content/themes/base/jquery.ui.all.css")
@Styles.Render("~/Content/themes/base/jquery.ui.datepicker.css")     

@Scripts.Render("~/scripts/app/EditCouponPartial.js")
@Scripts.Render("~/scripts/app/" + Path.GetFileNameWithoutExtension(Server.MapPath(VirtualPath)) + ".js")

    <fieldset>
        @Html.GetTitle("/Images/glyphicons/png/glyphicons_066_tags.png", new string[] { HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString() + "/" + ViewBag.Title })

        <div class="alert alert-info">
            Please select a coupon to update or add a new one.
            <div style='float: right' id="divRevoked">            
                Hide Revoked:
                <input type="checkbox" id="hideRevoked" style = "vertical-align: middle" @Html.Raw(ViewBag.hideRevoked == true ? "checked" : "") />
            </div>
        </div>

        <table width="100%">
            <tbody>
                <tr>
                    <td colspan="2">
                        Domain: @Html.DropDownList("domainSelect", domainList, new { @class = "input-medium", @id = "domainSelect" })
                       
                        @Html.Hidden("domainId", domainId)
                    </td>
                </tr>

                <tr>
                    <td width="65%" valign="top">
                         
                         <div style="height: 500px; border-style: solid; border-width: 1px; border-color: #DDDDDD"> 
                         <table class="table table-striped">
                              <thead>
                                <tr>
                                    <th>
                                        <a href="@String.Format("CouponSettings?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "eCommCouponID", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">eCommCouponID</a>
                                    </th>
                                    <th>
                                        <a href="@String.Format("CouponSettings?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "Value", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Value</a>
                                    </th>
                                    <th>
                                        <a href="@String.Format("CouponSettings?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "Type", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Type</a>                    
                                    </th>
                                    <th>
                                        <a href="@String.Format("CouponSettings?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "Uses", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Uses</a>                                        
                                    </th>
                                    <th>
                                        <a href="@String.Format("CouponSettings?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "RevokeStatus", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Revoked</a>                                                                                
                                    </th>
                                    <th>
                                        <a href="@String.Format("CouponSettings?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "DateRevoked", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Revoked at</a>                                                                                
                                    </th>
                                </tr>
                              </thead>
                              <tbody>
                                @{
                                    foreach (var coupon in Model.List)
                                    {
                                        <tr>
                                            <td>
                                                @Ajax.ActionLink(coupon.eCommCouponID, "EditViewCoupon", new { id = @coupon.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditCoupon" }, new { @class = "grid" })
                                            </td>
                                            <td>
                                                @Ajax.ActionLink(coupon.Value.ToString(), "EditViewCoupon", new { id = @coupon.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditCoupon" }, new { @class = "grid" })
                                            </td>
                                            <td>
                                                @Ajax.ActionLink(coupon.Type, "EditViewCoupon", new { id = @coupon.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditCoupon" }, new { @class = "grid" })
                                            </td>
                                            <td>
                                                @Ajax.ActionLink(coupon.Uses.ToString(), "EditViewCoupon", new { id = @coupon.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditCoupon" }, new { @class = "grid" })
                                            </td>
                                            <td>
                                                @(coupon.RevokeStatus ? Html.Raw("<i class=\"icon-check\"></i>") : Html.Raw(""))
                                            </td>
                                            <td>
                                                @Ajax.ActionLink((coupon.DateRevoked.HasValue ? coupon.DateRevoked.Value.ToString("MM/dd/yyyy") : " "), "EditViewCoupon", new { id = @coupon.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditCoupon" }, new { @class = "grid" })
                                            </td>
                                        </tr>
                                    }
                                }
                                    <tr>
                                        <td colspan="5">
                                            <div class="pagination" style="margin: 0">
                                                <ul>
                                                    @{
                                                        if (Model.PageIndex > 1)
                                                        { 
                                                            <li><a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex - 1, Model.SortColumn, Model.SortDirection)"><i class="icon-arrow-left"></i></a></li>
                                                        }

                                                        for (var i = 1; i <= WebApp.Classes.Statics.GetPages(Model.ResultCount); i++)
                                                        {
                                                            if (i == Model.PageIndex)
                                                            {
                                                                <li class="active"><a href="#">@i</a></li>
                                                            }
                                                            else
                                                            {
                                                                <li><a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", i, Model.SortColumn, Model.SortDirection)">@i</a></li>
                                                            }
                                                        }

                                                        if (Model.PageIndex != WebApp.Classes.Statics.GetPages(Model.ResultCount) && Model.ResultCount != 0)
                                                        { 
                                                            <li><a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex + 1, Model.SortColumn, Model.SortDirection)"><i class="icon-arrow-right"></i></a></li>
                                                        }                                    
                                                    }
                                                </ul>
                                            </div>                        
                                        </td>
                                        <td colspan="2" style="text-align: right">
                                            <br />
                                            <h5>Records: @Model.ResultCount</h5>
                                        </td>
                                    </tr>
                                </tbody>                          
                            </table>
                            </div>
                            <br />
                          
                          @{
                                if (new WebApp.Classes.UserRights(ViewBag.Title).FullControl)
                                { 
                                <div class="btn-group">    
                                    @Ajax.ImageActionLink("<i class=\"icon-plus-sign icon-white\"></i> Create New", "CreateCoupon", "Coupon", new { id = ViewBag.DomainID }, new AjaxOptions() { UpdateTargetId = "divEditCoupon" }, new { @id = "createCoupon", @class = "btn btn-inverse" })
                                </div>    
                                }
                            }
                    </td>
                    <td width="50%" valign="top">
                        <div id="divEditCoupon">

                        </div>                          
                    </td>
                </tr>
            </tbody>
        </table>

    </fieldset>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


